# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import codecs
import json

class AlldangdangPipeline(object):
    def __init__(self):
        self.file = codecs.open("E:\jiaocheng\F\scrapy2\dangdangall\data\dangdang_list3.json",'wb',encoding = 'utf-8')
    def process_item(self, item, spider):
        for j in range(0,len(item["name"])):
            names = item["name"][j]
            prices = item["price"][j]
            links = item["link"][j]
            shopnames = item["shopname"][j]
            comnums = item["comnum"][j]
            goods = {"name":names,"price":prices,"link":links,"shopname":shopnames,"comnum":comnums}
            i  = json.dumps(dict(goods),ensure_ascii=False)
            line = i + "\n"
            self.file.write(line)
        return item
    def close_spider(self,spider):
        self.file.close()